package lxh.com.union.logic_business.ui.customview;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.OnClick;
import lxh.com.union.R;

/**
 * Created by Administrator on 2017/12/18.
 */

public class CustomToolBar extends RelativeLayout {

    ImageView mIvBack;

    TextView mTvTitle;

    TextView mTvRight;

    public CustomToolBar(Context context) {
        this(context, null);
    }

    public CustomToolBar(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomToolBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View view = LayoutInflater.from(context).inflate(R.layout.layout_toolbar, this, true);
         mIvBack=view.findViewById(R.id.iv_back);
         mTvTitle=view.findViewById(R.id.tv_title);
         mTvRight=view.findViewById(R.id.tv_right);
        TypedArray typedArray=context.obtainStyledAttributes(attrs,R.styleable.Topbar);

        boolean leftIsVisible=typedArray.getBoolean(R.styleable.Topbar_top_leftVisibleable,true);
        mIvBack.setVisibility(leftIsVisible?VISIBLE:GONE);

        boolean rightIsVisible=typedArray.getBoolean(R.styleable.Topbar_top_rightVisibleable,false);
        mTvRight.setVisibility(rightIsVisible?VISIBLE:GONE);

        String topTitle=typedArray.getString(R.styleable.Topbar_top_title);
        mTvTitle.setText(topTitle);

        String topRightTitle=typedArray.getString(R.styleable.Topbar_top_right_title);
        mTvRight.setText(topRightTitle);

        typedArray.recycle();
    }

    public void setLeftClickListener(View.OnClickListener listener) {
        mIvBack.setOnClickListener(listener);
    }
}
